package com.vvlive.caibao.smartcity.ui;

import android.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vvlive.caibao.smartcity.base.BaseActivity;
import com.vvlive.caibao.smartcity.bean.TaskForLeave;
import com.vvlive.caibao.smartcity.utils.TimeUtil;
import com.vvlive.caibao.smartcity.view.CommonActionBar;
import com.vvlive.caibao.smartcity.view.DateTimePickerDialog;

import org.kymjs.kjframe.ui.BindView;

import smartcity.vvlive.caibao.com.smartc.R;

/**
 * Created by android on 2015/7/17.
 */
public class Activity_LeaveForTime extends BaseActivity {
    @BindView(id = R.id.leave_note)
    private EditText leave_note;
    @BindView(id = R.id.leave_time)
    private TextView leave_time;
    @BindView(id = R.id.leave_submit, click = true)
    private Button leave_submit;
    @BindView(id= R.id.leave_about, click = true)
    private TextView leave_about;
    @BindView(id= R.id.l_time , click = true)
    private RelativeLayout l_time;
    private long leaveTimeMillis;
    private String leavetime;
    private String reason;

    @Override
    protected int getContentViewRes() {
        return R.layout.activity_reqforleave;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        CommonActionBar commonActionBar = getCommonActionBar();
        commonActionBar.setTitle("请假");
        commonActionBar.setMoreVisible(false);
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()){
            case R.id.l_time:
                Leave_time();
                break;
            case R.id.leave_submit:
                submitQuestLeavetime();
                break;
            case R.id.leave_about:
                alert("请假要扣钱的吆");
                break;
        }
    }
    /**请假的时间*/
    private void Leave_time(){
        DateTimePickerDialog dateTimePickerDialog = new DateTimePickerDialog(this,System.currentTimeMillis());
        dateTimePickerDialog.setOnDateTimeSetListener(new DateTimePickerDialog.OnDateTimeSetListener() {
            @Override
            public void OnDateTimeSet(AlertDialog dialog, long date) {
                leaveTimeMillis = date;
                leavetime = TimeUtil.getTargetDateTime(leaveTimeMillis);
                leave_time.setText(leavetime);
            }
        });
        dateTimePickerDialog.show();
    }
    private void submitQuestLeavetime(){
        reason = leave_note.getText().toString();
        if (canApply()){
            alert(new TaskForLeave(reason,leavetime));
        }else {
            alert("请完善请假信息");
        }
    }
    private boolean canApply() {
        return !TextUtils.isEmpty(reason) && !TextUtils.isEmpty(leavetime)  ? true : false;
    }
}
